/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** Borrowed from AzuraStory, thanks guys!
 *
 * @author DestinyFate
 *
 * Magician 4th Job Advancement
 * 2081200.js
 */

importPackage(net.sf.odinms.client);

var status = 0;
var job;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && status == 0) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            if (!(cm.getJob().equals(MapleJob.FP_MAGE) ||
                cm.getJob().equals(MapleJob.IL_MAGE) ||
                cm.getJob().equals(MapleJob.PRIEST) ||
                cm.getJob().equals(MapleJob.FP_ARCHMAGE) ||
                cm.getJob().equals(MapleJob.IL_ARCHMAGE) ||
                cm.getJob().equals(MapleJob.BISHOP))) {
                cm.sendOk("Why do you want to see me? There is nothing you want to ask me.");
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.FP_ARCHMAGE)) {
                cm.sendNext("You became the best magician, #bArch Mage#k. Arch Mage can use its own power as well as Mana of nature just like \n#bInfinity#k or #bBig Bang#k" );
                //                cm.sendNext("This is not all about Arch Mage. Arch Mage is good at fire and poison element-based. It may change not only extreme element-based but also element-based of its own or enemies if you train. " );
                //                cm.sendNext("Don't forget that it all depends on how much you train." );
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.IL_ARCHMAGE)) {
                cm.sendNext("You became the best magician, #bArch Mage#k. Arch Mage can use its own power as well as Mana of nature just like \n#bInfinity#k or #bBig Bang#k" );
                //                cm.sendNext("This is not all about Arch Mage. Arch Mage is good at fire and poison element-based. It may change not only extreme element-based but also element-based of its own or enemies if you train. " );
                //                cm.sendNext("Don't forget that it all depends on how much you train." );
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.BISHOP)){
                cm.sendNext("You became the best magician #bBishop#k.  Bishop can use its own power as well as Mana of nature just like \n#bInfinity#k or #bBig Bang#k" );
                //                cm.sendNext("This is not all about Bishop. Bishop can borrow God's power. It may make strong castle element-based magic and even make the dead alive. " );
                //                cm.sendNext("Don't forget that it all depends on how much you train." );
                cm.dispose();
                return;
            }
            if (cm.getPlayer().getLevel() >= 120) {
                if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.FP_MAGE)) {
                    cm.sendSimple("You're qualified to be a true magician. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Arch Mage.#l\r\n#b#L1#  Let me think for a while.#l");
                } else if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.IL_MAGE)) {
                    cm.sendSimple("You're qualified to be a true magician. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Arch Mage.#l\r\n#b#L1#  Let me think for a while.#l");
                } else if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.PRIEST)) {
                    cm.sendSimple("You're qualified to be a true magician. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Bishop.#l\r\n#b#L1#  Let me think for a while.#l");
                } else {
                    cm.sendOk("Hmm...You have too many #bSP#k. You can't make the 4th job advancement with too many SP left.");
                    cm.dispose();
                    return;
                }
            } else {
                cm.sendOk("You're still weak to go to magician extreme road. If you get stronger, come back to me.");
                return;
            }
        } else if (status == 1) {
            if (selection == 0 && cm.getJob().equals(MapleJob.FP_MAGE)) {
                cm.changeJob(MapleJob.FP_ARCHMAGE);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(2121001,0,10);
                cm.teachSkill(2121006,0,10);
                cm.teachSkill(2121002,0,10);
                cm.sendNext("You became the best magician, the position of #bArch Mage#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else if (selection == 0 && cm.getJob().equals(MapleJob.IL_MAGE)) {
                cm.changeJob(MapleJob.IL_ARCHMAGE);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(2221001,0,10);
                cm.teachSkill(2221006,0,10);
                cm.teachSkill(2221002,0,10);
                cm.sendNext("You became the best magician, the position of #bArch Mage#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else if (selection == 0 && cm.getJob().equals(MapleJob.PRIEST)) {
                cm.changeJob(MapleJob.BISHOP);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(2321001,0,10);
                cm.teachSkill(2321005,0,10);
                cm.teachSkill(2321002,0,10);
                cm.sendNext("You became the best magician, the position of #bBishop#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else {
                cm.sendOk("You don't have to hesitate to be the best Magician..Whenever you decide, talk to me. If you're ready, I'll let you make the 4th job advancement.");
                cm.dispose();
            }
        }
    }
}